package com.bcqn.enums;

/**
 * PostType 帖子类型
 *
 * @author Kelly
 * @version v1.0
 * @date 2020/4/22 21:46
 */
public enum PostType {
    IDEA(1, "想法"),
    QUESTION(2, "问题");

    private final Integer value;
    private final String title;

    PostType(Integer value, String title) {
        this.value = value;
        this.title = title;
    }

    public Integer value() {
        return value;
    }

    public Integer getValue() {
        return value;
    }

    public String getTitle() {
        return title;
    }

    public String getTitle(Integer value) {
        return of(value).title;
    }

    public static PostType of(final Integer value) {
        for (PostType e : PostType.values()) {
            if (e.value != null && e.value.equals(value)) {
                return e;
            }
        }
        return null;
    }

    public static PostType nameOf(final String title) {
        for (PostType e : PostType.values()) {
            if (e.title.equals(title.trim())) {
                return e;
            }
        }
        return null;
    }


    @Override
    public String toString() {
        return this.title;
    }
}
